function peopleData(people) {
    console.log(people);
    $.ajax({
        url: $.getEnvUrl()+"/index.php?m=Admin&c=WechatEnt&a=addEmployee&token=ofanap1448334221",
        type: "POST",
        data: {
            userid: people.userid, //账号
            name: people.name, //姓名
            department: people.department, //部门
            position: people.position, //职位
            mobile: people.mobile, //手机
            gender: people.gender, //性别
            email: people.email, //邮箱
            weixinid: people.weixinid, //微信号
            // avatar_mediaid: people.avatar_mediaid, //头像
        },
        error: function () {
            alert('Error loading XML document');
        },
        success: function (data, status) { //如果调用php成功
            if(data.status == 1){
                alert('添加成功！');
            }else{
                alert('添加失败！');
            }
        }
    });
}




function addPeople(id) {

    // $(".updatePeople form").empty();
    // $(".addPeople form").empty();
    $(".content").addClass("hidden");
    $(".updatePeople").addClass("hidden");
    $(".addPeople").removeClass("hidden");
    var id = id;
    people.department = id;
    console.log(id);
}
$(document).ready(function () {
getSelect(1,$(this));
    $(".peoplePost").click(function () {
        people.name = $("#name").val();
        people.userid = $("#userid").val();
        people.gender = $("#gender option:selected").val();
        people.position = $("#position option:selected").val();
        people.weixinid = $("#weixinid").val();
        people.mobile = $("#mobile").val();
        people.email = $("#email").val();
        people.remark = $("#remark").val();
        //        console.log(people);
        //        $(".content").removeClass("hidden");
        //        $(".addPeople").addClass("hidden");
        peopleData(people);
    });



    $(".updatePost").click(function () {
        people.name = $("#name1").val();
        people.userid = $("#userid1").val();
        people.gender = $("#gender1 option:selected").val();
        people.department = $("#isvalue option:selected").val();
        people.position = $("#position1 option:selected").val();
        people.weixinid = $("#weixinid1").val();
        people.isadd = $('input[name="isadd"]:checked').val();
        people.mobile = $("#mobile1").val();
        people.email = $("#email1").val();
        people.remark = $("#remark1").val();
               console.log(people);
        //        $(".content").removeClass("hidden");
        //        $(".addPeople").addClass("hidden");
        updateData(people);
    });
});

function updatePeople(userid,id){
    // $(".updatePeople form").empty();
    // $(".addPeople form").empty();
    $(".content").addClass("hidden");
    $(".updatePeople").removeClass("hidden");
    $(".addPeople").addClass("hidden");
    var id = id;
    console.log(id);
    people.department = id;
getuser(userid);
}

function getuser(userid){
    $.ajax({
        url: $.getEnvUrl()+"/index.php?m=Admin&c=WechatEnt&a=getEmployee&token=ofanap1448334221&userid="+userid,
        type: "GET",
        data: {
        },
        error: function () {
            alert('Error loading XML document');
        },
        success: function (data, status) { //如果调用php成功
            if(data.errcode == 0){
                $("#name1").val(data.name);
                $("#userid1").val(data.userid);
                $("#gender1 option:selected").val(data.gender);
                $("#position1 option:selected").val(data.position);
                $("#weixinid1").val(data.weixinid);
                $("#mobile1").val(data.mobile);
                $("#email1").val(data.email);
                $("#remark1").val(data.remark);
            }else{
                alert('获取失败！');
            }
        }
    });
}
function updateData(people) {
    console.log(people);
    $.ajax({
        url: $.getEnvUrl()+"/index.php?m=Admin&c=WechatEnt&a=updateEmployee&token=ofanap1448334221",
        type: "POST",
        data: {
            userid: people.userid, //账号
            name: people.name, //姓名
            department: people.department, //部门
            position: people.position, //职位
            mobile: people.mobile, //手机
            isadd: people.isadd, //
            gender: people.gender, //性别
            email: people.email, //邮箱
            weixinid: people.weixinid, //微信号
            remark: people.remark, //备注
            // avatar_mediaid: people.avatar_mediaid, //头像
        },
        error: function () {
            alert('Error loading XML document');
        },
        success: function (data, status) { //如果调用php成功
            if(data.status == 1){
                alert('修改成功！');
            }else{
                alert('修改失败！');
            }
        }
    });
}

$(document).on("click",".delete",function(){
        if(window.confirm('是否删除')){
            var userid = $(this).attr('userid');
        var obj=$(this);
        $.ajax({
        url: $.getEnvUrl()+"/index.php?m=Admin&c=WechatEnt&a=deleteEmployee&token=ofanap1448334221&userid="+userid,
        type: "GET",
        data: {
        },
        error: function () {
            alert('Error loading XML document');
        },
        success: function (data, status) { //如果调用php成功
            if(data.status == 1){
              obj.closest('tr').remove();
            }else{
                alert('删除失败！');
            }
        }
    });
    }else{
        return false;
    }
        
});
